package jgcp.security;

import java.io.IOException;
import java.util.Properties;
/**
 * 
 * @Date 31/05/2009
 * @author Jie Zhao (288654)
 * @version 1.0
 */
public class PasswordAuthenticator{
	private static PasswordAuthenticator instance = new PasswordAuthenticator();
	private Properties prop = new Properties();
	private PasswordAuthenticator() {
		try {
			prop.load(this.getClass().getResourceAsStream("password.prop"));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static PasswordAuthenticator getInstance()
	{
		return instance;
	}
	
	public boolean checkUsername(String username)
	{
		return prop.containsKey(username);
	}
	
	public boolean login(String username,String password)
	{
		if(checkUsername(username) == false)
		{
			return false;
		}
		else
		{
			return prop.getProperty(username).equals(password);
		}
	}

	public static void main(String[] args) {
		PasswordAuthenticator pas = PasswordAuthenticator.getInstance();
		System.out.println(pas.login("admin", "admin"));
		
	}
}
